package com.quanquan.store.service;

import com.quanquan.store.entity.CouponType;
import com.quanquan.store.entity.CouponValueType;
import com.quanquan.store.repository.CouponTypeRepository;
import com.quanquan.store.repository.CouponValueTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:CouponTypeService
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/4/26 16:49
 * @Version 1.0
 */
@Service
public class CouponTypeService {

    private final CouponValueTypeRepository couponValueTypeRepository;
    private final CouponTypeRepository couponTypeRepository;

    @Autowired
    public CouponTypeService(CouponValueTypeRepository couponValueTypeRepository, CouponTypeRepository couponTypeRepository) {
        this.couponValueTypeRepository = couponValueTypeRepository;
        this.couponTypeRepository = couponTypeRepository;
    }

    /**
     * 券类型
     *
     * @return
     */
    public List<Object> findCouponType(){
        List<Object> objectList = new LinkedList<>();
        List<CouponType> couponTypes = couponTypeRepository.findByStatusRemoveAndAndStatusShow();
        for (CouponType couponType : couponTypes){
            Map<String,Object> map = new HashMap<>();
            map.put("id",couponType.getId());
            map.put("type",couponType.getType());
            map.put("name",couponType.getName());
            objectList.add(map);
        }
        return objectList;
    }

    /**
     * 价值类型
     *
     * @return
     */
    public List<Object> findCouponValueType(){
        List<Object> objectList = new LinkedList<>();
        List<CouponValueType> couponTypes = couponValueTypeRepository.findByStatusRemoveAndAndStatusShow();
        for (CouponValueType couponValueType : couponTypes){
            Map<String,Object> map = new HashMap<>();
            map.put("id",couponValueType.getId());
            map.put("valueType",couponValueType.getValueType());
            map.put("name",couponValueType.getName());
            objectList.add(map);
        }
        return objectList;
    }



}
